<?php
namespace app\home\controller;
use think\Db;
class Huimin extends HomeBase {

	public function getlist() {
		$map = array();
		$catid = input('catid','0','intval');
		$order = input('order');	// 排序
		$page = input('page','1','intval');		// 当前页
		$row = input('row','10','intval');		// 每页显示数据


		// 查询条件
		if ($catid) $map['catid'] = $catid;

		// 排序
		if (empty($order)) $order = 'create_time desc';
		
		// 分页
		$start = ($page-1) * $row;

		$list = array();
		if (!empty($map)) {
			$total = Db::name('Huimin')->where($map)->count('id');
			$list = Db::name('Huimin')->where($map)->order($order)->limit($start,$row)->field('id,title,catid,create_time')->select();
		} else {
			$total = Db::name('Huimin')->count('id');
			$list = Db::name('Huimin')->order($order)->limit($start,$row)->field('id,title,catid,create_time')->select();
		}
		if (empty($list)) 
			return json(array('status'=>0,'msg'=>'暂无数据'));
		else {
			foreach ($list as &$value) {
				$cat = Db::name('Hwcat')->where(array('id'=>$value['catid'],'mark'=>1))->field('title')->find();
				$value['cat'] = $cat['title'];
				// $danwei = Db::name('Danwei')->where('id',$value['bid'])->field('bname')->find();
				// $value['danwei'] = $danwei['bname'];
			}
			return json(array('status'=>1,'info'=>$list,'count'=>$total));
		}
	}

	public function getdetail() {
		$hmid = input('hmid');
		$hmid = intval($hmid);
		$info = Db::name('Huimin')->where('id',$hmid)->find();
		if (!$info)
			return json(array('status'=>0,'msg'=>'数据未找到'));
		$cat = Db::name('Hwcat')->where(array('id'=>$info['catid'],'mark'=>1))->field('title')->find();
		$info['cat'] = $cat['title'];
		$danwei = Db::name('Danwei')->where('id',$info['bid'])->field('bname')->find();
		$info['danwei'] = $danwei['bname'];
		// 刷新浏览次数
		Db::name('Huimin')->where('id',$hmid)->setInc('nums');
		return json(array('status'=>1,'info'=>$info));

	}
}